<?php
require_once '../setting.php';
require_once ROOTPATH . 'functions.php';
require_once INCLUDESPATH . 'db/User.php';
require_once INCLUDESPATH . 'db/UserDAO.php';

class UserDAOTest {

	function testInsert() {
		$user = new User();
		$user->setUsername("giginotes");
		$user->setNickname("blacksnow");
		$user->setPassword('21100000');
		$user->setEmail("giginotes@gmail.com");
		$user->setRealname("hutushen222");
		$user->setPhoto("default.png");
		$user->setGender();
		$user->setBirthday('1990-12-22');
		$user->setRegisterTime(formattime(time()));
		$user->setRole("user");
		$user->setQuestion("Who am I?");
		$user->setAnswer("hutushen222");
		$ud = new UserDAO();
		$ud->insert($user);
	}

	function testRetrieve() {
		$id = 7;
		$ud = new UserDAO();
		return $ud->retrieveById($id);
	}

	function testUpdate() {
		$ud = new UserDAO();
		$user = $ud->retrieveById(4);
		$user->setNickname("1234");
//		$user->setPassword("637521");
//		$user->setPhoto("haha");

		$user->setAnswer("1111");
		$ud->update($user);
	}

	function testDelete() {
		$ud = new UserDAO();
		$ud->delete(8);
	}

	function testRetrieveByProperty() {
		$ud = new UserDAO();
		return $ud->retrieveByProperty("photo", "default.png", "nickname");
	}
	function testRetrieveByProperties() {
		$ud = new UserDAO();
		$properties = array("realname" => "hutushen222");
		return $ud->retrieveByProperties($properties, "username");
	}

	function testRetrieveAll() {
		$ud = new UserDAO();
		return $ud->retrieveAll("nickname");
	}
}

$udt = new UserDAOTest();
echo "<pre>";
//$udt->testInsert();
//$udt->testUpdate();
//$udt->testDelete();
//print_r($udt->testRetrieveAll());
print_r($udt->testRetrieveByProperties());
//$users = array();
//if (is_null($udt->testRetrieve())) {
//	echo "haha";
//}  else {
//	print_r($udt->testRetrieve());
//}
echo "</pre>";
?>